const app = getApp();
Page({
  /**
   * 页面的初始数据
   */
  data: {
    videos: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    const videosJson = wx.getStorageSync("videos") || '[]';
    const videos = JSON.parse(videosJson);
    const baseUrl = app.globalData.baseUrl;
    const videoList = [];
    videos.forEach(function (item) {
      item.videoUrl = baseUrl + '/file/' + item.videoFileName;
      item.picUrl = baseUrl + '/file/' + item.picName;
      videoList.push(item);
    });

    this.setData({
      videos: videoList
    });
  },
  // 点击cover播放，其它视频结束
  videoPlay: function (e) {
    var _index = e.currentTarget.id
    this.setData({
      _index: _index
    })
    //停止正在播放的视频
    var videoContextPrev = wx.createVideoContext(this.data._index)
    videoContextPrev.stop();
    setTimeout(function () {
      //将点击视频进行播放
      var videoContext = wx.createVideoContext(_index)
      videoContext.play();
    }, 500)
  },
  videoErrorCallback: function(e) {
    wx.showToast({
      title: '视频加载出错',
      icon: 'none'
    })
  }
})